import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/h")
public class ServletH extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {HttpSession session=request.getSession(true);
        System.out.println(session.getId());
        session.setAttribute("s1","11111");
        String targetUrl=request.getContextPath()+"/f";
        String encodedUrl=response.encodeURL(targetUrl);
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out=response.getWriter();
        out.println("<a href='"+targetUrl+"'>普通跳转</a>");
        out.println("<a href='"+encodedUrl+"'>URL重写跳转</a>");


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}